<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>分页组件 laypage - Layui 文档</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script>;!function(){self!==parent&&(location.href="about:blank")}();</script>
  <link href="/public/layui/v/2.8.6/css/layui.css" rel="stylesheet">
  <link href="/public/static/dist/docs/2.8/css/global.css?v=16" rel="stylesheet">
  <script>
  (function(){if(window.JSON&&window.JSON.parse){var c=document.getElementsByTagName("head"),a=document.createElement("link");try{var b=JSON.parse(localStorage.layui)}catch(d){b={}}"dark"===b.themeMode&&(a.href="//res.sentcss.com/static/dist/docs/2.8/css/layui-theme-dark.css?v=16",a.rel="stylesheet",a.id="layuicss-theme-dark",c[0].appendChild(a))}})();
  </script>
</head>
<body>
<div class="layui-header ws-header ws-bg-light">
  <div class="layui-container">
    <div class="ws-logo">
      <a class="logo" href="../../../index.html">
        <img src="/public/static/images/layui/logo.png" alt="layui">
      </a>
    </div>
    <div class="ws-header-assist">
      <div class="layui-form layui-hide-xs ws-search" lay-filter="LAY-ws-header-component"></div>
      <div class="layui-hide-xs ws-notice"></div>
    </div>
    
    <div class="ws-header-menu">
      <ul class="layui-nav layui-bg-gray ws-bg-light" id="LAY_NAV_TOP">
        <li class="layui-nav-item" data-dir="docs">
          <a href="../index.html">组件</a> 
        </li>
        <li class="layui-nav-item" data-dir="notes">
          <a href="../../../notes/index.html">笔记</a> 
        </li>
        <li class="layui-nav-item layui-hide-xs">
          <a href="https://gitee.com/layui/layui/issues" target="_blank" rel="nofollow">社区</a>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">
            <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>--> 
            生态
          </a>
          <dl class="layui-nav-child layui-nav-child-r" style="margin-right: -21px;">  
            <dd class="layui-hide-sm layui-show-xs" lay-unselect>
              <a href="https://gitee.com/layui/layui/issues" target="_blank" rel="nofollow">社区</a>
              <hr>
            </dd>
            <dd lay-unselect>
              <a href="https://dev.layuion.com/extend/" target="_blank">Layui 第三方扩展组件</a>
            </dd>
            <dd lay-unselect>
              <a href="https://github.com/Sight-wcg/layui-theme-dark" target="_blank" lay-unselect>
                Layui 深色主题 <span>(社区贡献)</span>
              </a>
            </dd>
            <dd lay-unselect>
              <a href="https://gitee.com/layui/layui-vue/" target="_blank" lay-unselect>
                Layui of Vue <span>(他人实现)</span>
              </a>
            </dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">2.8.6</a>
          <dl class="layui-nav-child layui-nav-child-c">  
            <dd lay-unselect class="layui-this"><a href="../../../index.html">2.8.6</a></dd>
            <dd lay-unselect><a href="../../../2.7/index.html">2.7.6</a></dd>
          </dl>
        </li>
      </ul>
      <div class="ws-header-more">
        <i class="layui-icon layui-icon-shrink-right"></i>
      </div>
      <div class="ws-header-tool ws-bg-light">
        <div class="layui-form ws-header-theme" lay-filter="header-theme">
          <input type="checkbox" name="theme-mode" id="ID-header-theme-mode" lay-filter="header-theme-mode" lay-skin="switch">
          <div lay-checkbox>
            <i class="layui-icon layui-icon-moon"></i> | 
            <i class="layui-icon layui-icon-light"></i>
          </div>
        </div>
        <div>
          <a href="https://github.com/layui/layui" target="_blank" title="Github">
            <i class="layui-icon layui-icon-github layui-font-20"></i>
          </a>
        </div>
        <div>
          <a href="https://gitee.com/layui/layui" target="_blank" title="Gitee">
            <i class="layui-icon layui-icon-gitee layui-font-20" style="color: #C71D23;"></i>
            <!--<img src="https://gitee.com/static/images/logo-en.svg" width="21">-->
          </a>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 让 IE8/9 兼容响应式栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
 
<div class="layui-container ws-container">
  
<div class="layui-panel ws-menu">
  <ul class="layui-menu layui-menu-lg ws-docs-menu">
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">基础</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../index.html">
              <span>开始使用</span> 
              <span class="layui-font-12 layui-font-gray">Getting Started</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../base.html">
              <span>底层方法</span>
              <span class="layui-font-12 layui-font-gray">Base Function</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../modules.html">
              <span>模块系统</span>
              <span class="layui-font-12 layui-font-gray">Modules</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../versions.html">
              <span>更新日志</span>
              <span class="layui-font-12 layui-font-gray">Versions</span>
              <span class="layui-badge-dot"></span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">布局</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layout/index.html">
              <span>框体</span>
              <span class="layui-font-12 layui-font-gray">Layout</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layout/grid.html">
              <span>栅格</span>
              <span class="layui-font-12 layui-font-gray">Grid</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">通用</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../color/index.html">
              <span>颜色</span>
              <span class="layui-font-12 layui-font-gray">Color</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../button/index.html">
              <span>按钮</span>
              <span class="layui-font-12 layui-font-gray">Button</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../icon/index.html">
              <span>图标</span>
              <span class="layui-font-12 layui-font-gray">Icon</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../anim/index.html">
              <span>动画</span>
              <span class="layui-font-12 layui-font-gray">Anim</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">表单</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/index.html">
              <span>表单组件</span>
              <span class="layui-font-12 layui-font-gray">Form</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/input.html">
              <span>输入框</span>
              <span class="layui-font-12 layui-font-gray">Input / Textarea</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/select.html">
              <span>选择框</span>
              <span class="layui-font-12 layui-font-gray">Select</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/checkbox.html">
              <span>复选框</span>
              <span class="layui-font-12 layui-font-gray">Checkbox</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../form/radio.html">
              <span>单选框</span>
              <span class="layui-font-12 layui-font-gray">Radio</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">展示</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../table/index.html">
              <span>表格</span>
              <span class="layui-font-12 layui-font-gray">Table</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="index.html">
              <span>分页</span>
              <span class="layui-font-12 layui-font-gray">Laypage</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../treeTable/index.html">
              <span>树形表格</span>
              <span class="layui-font-12 layui-font-gray">TreeTable</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../nav/index.html">
              <span>导航菜单</span>
              <span class="layui-font-12 layui-font-gray">Nav</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../menu/index.html">
              <span>基础菜单</span>
              <span class="layui-font-12 layui-font-gray">Menu</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../tab/index.html">
              <span>选项卡</span>
              <span class="layui-font-12 layui-font-gray">Tab</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../badge/index.html">
              <span>徽章</span>
              <span class="layui-font-12 layui-font-gray">Badge</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../auxiliar/index.html">
              <span>辅助</span>
              <span class="layui-font-12 layui-font-gray">Blockquote / Fieldset / hr</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../class/index.html">
              <span>公共类</span>
              <span class="layui-font-12 layui-font-gray">Class</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../panel/index.html">
              <span>面板</span>
              <span class="layui-font-12 layui-font-gray">Panel / Card / Collapse</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../progress/index.html">
              <span>进度条</span>
              <span class="layui-font-12 layui-font-gray">Progress</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../timeline/index.html">
              <span>时间线</span>
              <span class="layui-font-12 layui-font-gray">Timeline</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../fixbar/index.html">
              <span>固定条</span>
              <span class="layui-font-12 layui-font-gray">Fixbar</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../tree/index.html">
              <span>树组件</span>
              <span class="layui-font-12 layui-font-gray">Tree</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../carousel/index.html">
              <span>轮播</span>
              <span class="layui-font-12 layui-font-gray">Carousel</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../flow/index.html">
              <span>流加载</span>
              <span class="layui-font-12 layui-font-gray">Flow</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../code/index.html">
              <span>代码预览组件</span>
              <span class="layui-font-12 layui-font-gray">Code</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">交互</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../layer/index.html">
              <span>弹出层</span>
              <span class="layui-font-12 layui-font-gray">Layer</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../laydate/index.html">
              <span>日期与时间选择</span>
              <span class="layui-font-12 layui-font-gray">Laydate</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../upload/index.html">
              <span>上传</span>
              <span class="layui-font-12 layui-font-gray">Upload</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../dropdown/index.html">
              <span>下拉菜单</span>
              <span class="layui-font-12 layui-font-gray">Dropdown</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../colorpicker/index.html">
              <span>颜色选择器</span>
              <span class="layui-font-12 layui-font-gray">Colorpicker</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../transfer/index.html">
              <span>穿梭框</span>
              <span class="layui-font-12 layui-font-gray">Transfer</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../slider/index.html">
              <span>滑块</span>
              <span class="layui-font-12 layui-font-gray">Slider</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../rate/index.html">
              <span>评分</span>
              <span class="layui-font-12 layui-font-gray">Rate</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">其他</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="../laytpl/index.html">
              <span>模板引擎</span>
              <span class="layui-font-12 layui-font-gray">Laytpl</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="../util/index.html">
              <span>工具模块</span>
              <span class="layui-font-12 layui-font-gray">Util</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    
  </ul>
</div>

  <div class="ws-content">
    <div class="layui-text ws-text" id="WS-text">
      <h1>分页组件</h1>
<blockquote class="layui-elem-quote">
<p>分页组件 <code>laypage</code> 提供了前端的分页逻辑，使得我们可以很灵活处理不同量级的数据，从而提升渲染效率。</p>
</blockquote class="layui-elem-quote">
<h2 id="examples" lay-toc="{hot: true}" style="margin-bottom: 0;">示例</h2>
<div class="ws-detail">
<pre class="layui-code" lay-options="{preview: true, text: {preview: '普通用法'}, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-normal-1"></div>
<div id="demo-laypage-normal-2"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 普通用法
  laypage.render({
    elem: 'demo-laypage-normal-1',
    count: 50 // 数据总数
  });
  laypage.render({
    elem: 'demo-laypage-normal-2',
    count: 100 // 数据总数
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-theme" class="ws-anchor ws-bold">自定义主题</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-theme-1"></div>
<div id="demo-laypage-theme-2"></div>
<div id="demo-laypage-theme-3"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 自定义主题
  laypage.render({
    elem: 'demo-laypage-theme-1',
    count: 100,
    theme: '#1E9FFF'
  });
  laypage.render({
    elem: 'demo-laypage-theme-2',
    count: 100,
    theme: '#FF5722'
  });
  laypage.render({
    elem: 'demo-laypage-theme-3',
    count: 100,
    theme: '#FFB800'
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-text" class="ws-anchor ws-bold">自定义文本</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-text"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 自定义文本
  laypage.render({
    elem: 'demo-laypage-text',
    count: 100,
    first: '首页',
    last: '尾页',
    prev: '<em>←</em>',
    next: '<em>→</em>'
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-pn-hide" class="ws-anchor ws-bold">不显示上一页、下一页</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-pn-hide"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 不显示上一页、下一页
  laypage.render({
    elem: 'demo-laypage-pn-hide',
    count: 100,
    prev: false,
    next: false
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-pn-show" class="ws-anchor ws-bold">只显示上一页、下一页、当前页</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-pn-show"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  var layer = layui.layer;
  // 只显示上一页、下一页、当前页
  laypage.render({
    elem: 'demo-laypage-pn-show',
    count: 50,
    groups: 1,
    first: false,
    last: false,
    layout: ['prev', 'page','next'],
    jump: function(obj, first){
      // 首次不执行
      if(!first){
        layer.msg('第 '+ obj.curr +' 页');
      }
    }
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-layout" class="ws-anchor ws-bold">自定义排版</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-layout-1"></div>
<div id="demo-laypage-layout-2"></div>
<div id="demo-laypage-layout-3"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 自定义排版
  laypage.render({
    elem: 'demo-laypage-layout-1',
    count: 1000,
    layout: ['limit', 'prev', 'page', 'next']
  });
  laypage.render({
    elem: 'demo-laypage-layout-2',
    count: 1000,
    layout: ['prev', 'next', 'page']
  });
  laypage.render({
    elem: 'demo-laypage-layout-3',
    count: 1000,
    layout: ['page', 'count']
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-limits" class="ws-anchor ws-bold">自定义每页条数的选择项</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-limits"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 自定义每页条数的选择项
  laypage.render({
    elem: 'demo-laypage-limits',
    count: 1000,
    limit: 100,
    limits: [100, 300, 500],
    layout: ['prev', 'page', 'next', 'limit']
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-all" class="ws-anchor ws-bold">完整显示</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-all"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 完整显示
  laypage.render({
    elem: 'demo-laypage-all', // 元素 id
    count: 100, // 数据总数
    layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
    jump: function(obj){
      console.log(obj);
    }
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-hash" class="ws-anchor ws-bold">高级 - 开启 HASH</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-hash"></div>
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 开启 HASH
  laypage.render({
    elem: 'demo-laypage-hash',
    count: 500,
    curr: location.hash.replace('#!curr=', ''), // 初始获取 hash 值为 curr 的当前页
    hash: 'curr' // 自定义 hash 名称
  });
});
</script>
  </textarea>
</pre>
<h3 id="demo-data" class="ws-anchor ws-bold">高级 - 将一段已知数组分页展示</h3>
<pre class="layui-code" lay-options="{preview: true, layout: ['preview', 'code'], tools: ['full']}">
  <textarea>
<div id="demo-laypage-data"></div>
<div id="demo-laypage-data-view"></div> 
<!-- import layui -->
<script>
layui.use(function(){
  var laypage = layui.laypage;
  // 将一段已知数组分页展示
  var data = ["北京","上海","广州","深圳","杭州","长沙","合肥","宁夏","成都","西安","南昌","上饶","沈阳","济南","厦门","福州","九江","宜春","赣州","宁波","绍兴","无锡","苏州","徐州","东莞","佛山","中山","成都","武汉","青岛","天津","重庆","南京","九江","香港","澳门","台北"]; // 测试数据
  laypage.render({
    elem: 'demo-laypage-data',
    count: data.length,
    jump: function(obj){
      // 模拟渲染
      document.getElementById('demo-laypage-data-view').innerHTML = function(){
        var arr = [];
        var thisData = data.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
        layui.each(thisData, function(index, item){
          arr.push(item);
        });
        return arr.join('，');
      }();
    }
  });
});
</script>
  </textarea>
</pre>
</div>
<h2 id="api" lay-toc="{}">API</h2>
<table class="layui-table">
<thead>
<tr>
<th>API</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>var laypage = layui.laypage</td>
<td>获得 <code>laypage</code> 模块。</td>
</tr>
<tr>
<td><a href="index.html#render">laypage.render(options)</a></td>
<td>laypage 组件渲染，核心方法。</td>
</tr>
</tbody>
</table class="layui-table">
<h2 id="render" lay-toc="{level: 2}">渲染</h2>
<p><code>laypage.render(options);</code></p>
<ul>
<li>参数 <code>options</code> : 基础属性配置项。<a href="index.html#options">#详见属性</a></li>
</ul>
<h2 id="options" lay-toc="{level: 2, hot: true}">属性</h2>
<div>
<table class="layui-table">
  <colgroup>
    <col width="150">
    <col>
    <col width="100">
    <col width="100">
  </colgroup>
  <thead>
    <tr>
      <th>属性名</th>
      <th>描述</th>
      <th>类型</th>
      <th>默认值</th>
    </tr> 
  </thead>
  <tbody>
    <tr>
<td>elem</td>
<td>
<p>绑定分页容器。值可以是容器 <code>id</code> 或 DOM 对象。如：</p>
<ul>
<li><code>elem: 'id'</code> 注意：这里不能加 <code>#</code> 号</li>
<li><code>elem: document.getElementById('id')</code></li>
</ul>
</td>
<td>string<br>DOM</td>
<td>-</td>
    </tr>
    <tr>
<td>count</td>
<td>
<p>数据总数。一般通过后端得到</p>
</td>
<td>number</td>
<td>-</td>
    </tr>
    <tr>
<td>limit</td>
<td>
<p>每页显示的条数。</p>
</td>
<td>number</td>
<td>
<p><code>10</code></p>
</td>
    </tr>
    <tr>
<td>limits</td>
<td>
<p>每页条数的选择项。 若 <code>layout</code> 参数开启了 <code>limit</code> ，则会出现每页条数的 select 选择框</p>
</td>
<td>array</td>
<td>
<p><code>[10,…,50]</code></p>
</td>
    </tr>
    <tr>
<td>curr</td>
<td>
<p>初始化当前页码。</p>
</td>
<td>number</td>
<td>
<p><code>1</code></p>
</td>
    </tr>
    <tr>
<td>groups</td>
<td>
<p>连续出现的页码数量</p>
</td>
<td>number</td>
<td>
<p><code>5</code></p>
</td>
    </tr>
    <tr>
<td>prev</td>
<td>
<p>自定义“上一页”的内容，支持传入普通文本和 HTML</p>
</td>
<td>string</td>
<td>
<p><code>上一页</code></p>
</td>
    </tr>
    <tr>
<td>next</td>
<td>
<p>自定义“下一页”的内容，用法同上。</p>
</td>
<td>string</td>
<td>
<p><code>下一页</code></p>
</td>
    </tr>
    <tr>
<td>first</td>
<td>
<p>自定义“首页”的内容，用法同上。</p>
</td>
<td>string</td>
<td>
<p><code>1</code></p>
</td>
    </tr>
    <tr>
<td>last</td>
<td>
<p>自定义“尾页”的内容，用法同上。</p>
</td>
<td>string</td>
<td>
<p><em class="layui-text-em">自动获得</em></p>
</td>
    </tr>
    <tr>
<td>layout</td>
<td>
<p>自定义分页功能区域排版。可自由排列，可选值有：</p>
<ul>
<li><code>count</code> 数据总数区域</li>
<li><code>prev</code> 上一页区域</li>
<li><code>page</code> 分页区域</li>
<li><code>next</code> 下一页区</li>
<li><code>limit</code> 条目选项区域</li>
<li><code>refresh</code> 页面刷新区</li>
<li><code>skip</code> 快捷跳页区</li>
</ul>
</td>
<td>array</td>
<td>
<p><button class="layui-btn layui-btn-sm layui-btn-primary" lay-layer="{
  title: 'layout 属性默认值',
  content: '<div>layout: [\'prev\',\'page\',\'next\']</div>'
}">查看默认值</button></p>
</td>
    </tr>
    <tr>
<td>theme</td>
<td>
<p>自定义主题。支持传入：颜色值或任意普通字符。如：</p>
<ul>
<li><code>theme: '#c00'</code> 直接设置当前页按钮背景色</li>
<li><code>theme: 'xxx'</code> 会生成 <code>class=&quot;layui-laypage-xxx&quot;</code> 的 CSS 类，以便自定义主题</li>
</ul>
</td>
<td>string</td>
<td>-</td>
    </tr>
    <tr>
<td>hash</td>
<td>
<p>设置 <code>hash</code> 名称。设置该属性后，点击分页将会自动对当前 <code>url</code> 追加：<code>#{hash}={curr}</code>，从而在页面刷新时初始化当前页码。<a href="index.html#demo-hash">#详细用法参考示例</a></p>
</td>
<td>string</td>
<td>-</td>
    </tr>
    <tr>
<td colspan="4" style="text-align: center"> 
<div id="options.callback" lay-pid="options" class="ws-anchor">
<p><a href="index.html#options.callback">回调函数</a></p>
</div>
</td>
    </tr>
    <tr>
<td>
<p><a href="index.html#options.jump">jump</a></p>
</td>
<td colspan="3">
<div id="options.jump" lay-pid="options" class="ws-anchor">分页跳转后的回调函数。函数返回两个参数：</div>
<ul>
<li>参数 <code>obj</code> : 当前分页相关的所有选项值</li>
<li>参数 <code>first</code> : 是否首次渲染，一般用于初始加载的判断</li>
</ul>
<pre><code class="layui-code">laypage.render({
  elem: 'id',
  count: 70, // 数据总数，从后端得到
  jump: function(obj, first){
    console.log(obj.curr); // 得到当前页，以便向服务端请求对应页的数据。
    console.log(obj.limit); // 得到每页显示的条数
    
    // 首次不执行
    if(!first){
      // do something
    }
  }
});
</code></pre>
</td>
    </tr>
  </tbody>
</table>

</div>
<h2>小贴士</h2>
<p>laypage 组件只负责分页本身的逻辑，具体的数据请求及对应的视图渲染需要另外去完成。laypage 不仅能应用在一般的异步分页上，还可直接对一段已知数据进行分页展现，如 table 组件的分页就是采用的 laypage。</p>

    </div>
    <div class="ws-text-tools">
      
      <a href="https://github.com/layui/layui/edit/2.x/docs/laypage/index.md" rel="nofollow" target="_blank" title="在 Github 上编辑此文档">
        <i class="layui-icon layui-icon-edit"></i>
      </a>
      
    </div>
  </div>
</div>
<div class="ws-menu-bar layui-bg-green layui-hide">
  <i class="layui-icon layui-icon-spread-left"></i>
</div>
  
<div class="layui-footer ws-footer">
  <p>
    Copyright &copy; 2023 <a href="../../../index.html">Layui</a> MIT Licensed</p>
  <p id="LAY-footer-info">
    <a href="https://gitee.com/layui/layui/blob/main/DISCLAIMER.md" rel="nofollow" target="_blank">免责声明</a> 
    <a href="https://github.com/layui/layui/blob/main/LICENSE" rel="nofollow" target="_blank">开源协议</a>
    <a href="https://gitee.com/layui/" target="_blank">开源生态</a>
    <a href="https://codepen.io/layui/pen/bGxZXrd" rel="nofollow" target="_blank">在线测试</a>
    <a href="https://gitee.com/layui/layui/issues" rel="nofollow" target="_blank">社区交流</a>
  </p>
  <p>
    <span>
      鸣谢：
      <a href="https://www.upyun.com/?invite=SJ0wu6g2-&referer=layui" target="_blank" sponsor="upyun" style="color: #23A7E8;">
        <strong>又拍云</strong>
      </a>
      <a href="https://gitee.com/?referer=layui" target="_blank" sponsor="Gitee" style="color:#C71D23;">
        <strong>Gitee</strong>
      </a>
      <a href="https://www.iconfont.cn/?referer=layui" target="_blank" sponsor="Gitee" style="color: #9B16FF;">
        <strong>iconfont</strong>
      </a>
    </span>
  </p>
</div>
<div class="ws-shade"></div>
 
<script src="/public/layui/v/2.8.6/layui.js"></script>
<script>
layui.config({
  base: '//res.sentcss.com/static/dist/docs/2.8/modules/',
  version: '16',
  res: '//res.sentcss.com/static/dist/docs/',
  curl: ''
}).use('global',function(w){w.a||w.r&&w.r()});
</script>
 
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?363b2abe8678eec8a6850500ea63a63b";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</body>
</html>